home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / StatusMonitor / UViewStatusInfo.cp < prev    next >
Encoding:
Text File  |  1995-07-28  |  26.3 KB  |  1,005 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        UViewStatusInfo.cp
  3.  
  4.     Contains:    *** put contents here ***
  5.  
  6.     Written by:    Steve Datnow
  7.  
  8.     Copyright:    © 1992 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         8/24/93        SLD        Add bullettext
  13.         8/18/93        SLD        Add FixedPopup
  14.         4/2/93      KSS        Add status bar item.
  15.         1/21/92     SLD        *** put comment here ***
  16.  
  17.     To Do:
  18. */
  19.  
  20. #ifndef __UViewStatusInfo__
  21. #include "UViewStatusInfo.h"
  22. #endif
  23.  
  24. #ifndef __UMACAPPUTILITIES__
  25. #include "UMacAppUtilities.h"
  26. #endif
  27.  
  28. #ifndef __UDOCUMENTSecondStomach__
  29. #include "UDocumentSecondStomach.h"
  30. #endif
  31.  
  32. #ifndef __TOOLUTILS__
  33. #include <ToolUtils.h>
  34. #endif
  35.  
  36. #ifndef __PACKAGES__
  37. #include <Packages.h>
  38. #endif
  39.  
  40. #ifndef __FONTS__
  41. #include "Fonts.h"
  42. #endif
  43.  
  44. #ifndef __STDIO__
  45. #include <StdIO.h>
  46. #endif
  47.  
  48. /****************************** Global Initialization Procedure ******************************/
  49.  
  50. #pragma segment DlgInit
  51.  
  52. pascal void InitUViewStatusInfo()
  53. {
  54.     // So the linker doesn't dead strip class info 
  55.     macroDontDeadStrip(TViewStrStatusInfo);
  56.     macroDontDeadStrip(TViewNumStatusInfo);
  57.     macroDontDeadStrip(TViewlongDateStatusInfo);
  58.     macroDontDeadStrip(TViewshortDateStatusInfo);
  59.     macroDontDeadStrip(TViewabbrevDateStatusInfo);
  60.     macroDontDeadStrip(TViewTimeStatusInfo);
  61.     macroDontDeadStrip(TViewElaspedTimeStatusInfo);
  62.     macroDontDeadStrip(TViewlogStatusInfo);
  63.     macroDontDeadStrip(TViewMonitorStatus);
  64.     macroDontDeadStrip(TViewNumKilobytesStatusInfo);
  65.     macroDontDeadStrip(TLeftFilledStatusBarView);
  66.     macroDontDeadStrip(TMonitorButton);    
  67.     macroDontDeadStrip(TViewNumBytesStatusInfo);
  68.         
  69.     macroDontDeadStrip(TDialogViewConfig);    
  70.     macroDontDeadStrip(TFixedPopup);
  71.     
  72.     macroDontDeadStrip(TBulletEditText);
  73. }
  74.  
  75. /***********************************|****************************************/
  76.  
  77. TViewMonitorStaticText::TViewMonitorStaticText()
  78. {
  79. }
  80.  
  81. /***********************************|****************************************/
  82.  
  83. pascal void TViewMonitorStaticText::IViewMonitorStaticText(TView* itsSuperView,
  84.                                     const VPoint& itsLocation,
  85.                                     const VPoint& itsSize,
  86.                                     SizeDeterminer itsHSizeDet,
  87.                                     SizeDeterminer itsVSizeDet,
  88.                                     ResNumber itsRsrcID,
  89.                                     short itsIndex)
  90. {
  91.     inherited::IStaticText ( itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsRsrcID, itsIndex );
  92. }
  93.  
  94. /***********************************|****************************************/
  95.  
  96. pascal void TViewMonitorStaticText::GetText(CStr255& theText)
  97. {
  98.     static Str255 gViewMonitorEmptyStaticTextStr = "\p?";
  99.     
  100.     if ( fDataHandle )
  101.         CopyStr255((**((String255Handle)fDataHandle)), (Ptr)&theText);
  102.     else
  103.         theText = gViewMonitorEmptyStaticTextStr;
  104. }
  105.  
  106. /***********************************|****************************************/
  107.  
  108. pascal void TViewNumStatusInfo::DoUpdate(ChangeID theChange, 
  109.                               TObject* changedObject,
  110.                               TObject* changedBy,
  111.                               TDependencySpace* dependencySpace)
  112.  
  113. {
  114.     long theNum; 
  115.     long numSize = sizeof(theNum);
  116.     CStr255 theValue;
  117.     Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &theNum, numSize,typeLongInteger);
  118.     if (gotInfo)
  119.         NumToString(theNum, theValue);
  120.     else
  121.         theValue = "";
  122.         
  123.     SetText(theValue,kRedraw);
  124.     inherited::DoUpdate(theChange,changedObject,changedBy, dependencySpace);
  125. }
  126.  
  127. /***********************************|****************************************/
  128.  
  129. pascal void TViewNumKilobytesStatusInfo::DoUpdate(ChangeID theChange, 
  130.                               TObject* changedObject,
  131.                               TObject* changedBy,
  132.                               TDependencySpace* dependencySpace)
  133.  
  134. {
  135.     long theNum; 
  136.     long numSize = sizeof(theNum);
  137.     CStr255 theValue;
  138.     Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &theNum, numSize, typeLongInteger);
  139.     if (gotInfo) 
  140.     {
  141.         NumToString(theNum / 1024, theValue);
  142.         theValue += "K";
  143.     }
  144.     else
  145.         theValue = " ";
  146.     
  147.     
  148.     SetText(theValue,kRedraw);
  149.     inherited::DoUpdate(theChange,changedObject,changedBy, dependencySpace);
  150. }
  151.  
  152. /***********************************|****************************************/
  153.  
  154. /*
  155. void FormatNumBytes(unsigned long num,unsigned long d,CStr255& theValue,CStr255 suffix) {
  156.     unsigned long n;
  157.     short l;
  158.     
  159.     n = num/(d/10);
  160.  
  161.     NumToString(n, theValue);
  162.     l = theValue.Length();
  163.     if (theValue[l] == '0')
  164.         theValue[0] = l - 1;
  165.     else
  166.         theValue.Insert(".",theValue.Length()-1);
  167.     theValue += suffix;
  168. }
  169. */
  170.  
  171. pascal void TViewNumBytesStatusInfo::DoUpdate(ChangeID theChange, 
  172.                               TObject* changedObject,
  173.                               TObject* changedBy,
  174.                               TDependencySpace* dependencySpace)
  175.  
  176. {
  177.     unsigned long theNum; 
  178.     long numSize = sizeof(theNum);
  179.     CStr255 theValue = "";
  180.     Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &theNum, numSize, typeLongInteger);
  181.     if (gotInfo) 
  182.     {
  183.         if (theNum < 1024)
  184.             NumToString(theNum,theValue);
  185.         else if (theNum < 1048576) {
  186.                 theValue[0] = sprintf ( (char*) &theValue[1], "%.1fK", ((float) theNum ) / 1024.0);    
  187.         }
  188.         else if (theNum < (1073741824)) {
  189.                 theValue[0] = sprintf ( (char*) &theValue[1], "%.1fMB", ((float) theNum ) / 1048576.0);
  190.  
  191.         }
  192.         else {
  193.                 theValue[0] = sprintf ((char*)  &theValue[1], "%.1fGB", ((float) theNum ) / 1073741824.0);
  194.  
  195.         }
  196.     }
  197.     
  198.     SetText(theValue,kRedraw);
  199.     inherited::DoUpdate(theChange,changedObject,changedBy, dependencySpace);
  200. }
  201.  
  202. /***********************************|****************************************/
  203.  
  204. pascal void TViewDateStatusInfo::DoUpdate(ChangeID theChange, 
  205.                               TObject* changedObject,
  206.                               TObject* changedBy,
  207.                               TDependencySpace* dependencySpace)
  208.  
  209. {
  210.     long theNum; 
  211.     long numSize = sizeof(theNum);
  212.     CStr255 theValue;
  213.     Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &theNum, numSize, typeLongInteger);
  214.     if (gotInfo) {
  215.         DateForm df = GetDateFormat();
  216.         IUDateString(theNum,df,theValue);
  217.     }
  218.     else
  219.         theValue = "";
  220.         
  221.     SetText(theValue,kRedraw);
  222.     inherited::DoUpdate(theChange,changedObject,changedBy, dependencySpace);
  223. }
  224.  
  225. /***********************************|****************************************/
  226.  
  227. pascal void TViewTimeStatusInfo::DoUpdate(ChangeID theChange, 
  228.                               TObject* changedObject,
  229.                               TObject* changedBy,
  230.                               TDependencySpace* dependencySpace)
  231.  
  232. {
  233.     long theNum; 
  234.     long numSize = sizeof(theNum);
  235.     CStr255 theValue;
  236.     Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &theNum, numSize,typeLongInteger);
  237.     if (gotInfo)
  238.         IUTimeString( theNum, false, theValue);
  239.     else
  240.         theValue = "";
  241.         
  242.     SetText(theValue,kRedraw);
  243.     inherited::DoUpdate(theChange,changedObject,changedBy, dependencySpace);
  244. }
  245.  
  246. /***********************************|****************************************/
  247.  
  248. pascal void TViewTimeStatusWithSecondsInfo::DoUpdate(ChangeID theChange, 
  249.                               TObject* changedObject,
  250.                               TObject* changedBy,
  251.                               TDependencySpace* dependencySpace)
  252.  
  253. {
  254.     long theNum; 
  255.     CStr255 theValue;
  256.     
  257.     Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &theNum, sizeof(theNum), typeLongInteger);
  258.     if (gotInfo)
  259.         IUTimeString(theNum, true, theValue);
  260.     else
  261.         theValue = "";
  262.         
  263.     SetText(theValue,kRedraw);
  264.     inherited::DoUpdate(theChange,changedObject,changedBy, dependencySpace);
  265. }
  266.  
  267. /***********************************|****************************************/
  268.  
  269. pascal void TViewElaspedTimeStatusInfo::DoUpdate(ChangeID theChange, 
  270.                               TObject* changedObject,
  271.                               TObject* changedBy,
  272.                               TDependencySpace* dependencySpace)
  273.  
  274. {
  275.     unsigned long theNum; 
  276.     long numSize = sizeof(theNum);
  277.     CStr255 theValue;
  278.     Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &theNum, numSize,typeLongInteger);
  279.     if (gotInfo) {
  280.         long days = theNum / 86400;
  281.         long hours = (theNum - (days*86400)) / 3600;
  282.         long minutes = (theNum - (days*86400) - (hours*3600)) / 60;
  283.         long seconds = theNum % 60;
  284.         sprintf ((char*) &(theValue[1]), "%4d %2d:%02d:%02d", days, hours, minutes,seconds);
  285.         theValue.Length() = strlen((char*) &(theValue[1]));
  286.         for (short i=1;i <= theValue.Length();i++)
  287.             if (theValue[i] == ' ' )    // Regular space
  288.                 theValue[i] =' ';        // Option-space
  289.     }
  290.     else
  291.         theValue = "";
  292.         
  293.     SetText(theValue,kRedraw);
  294.     inherited::DoUpdate(theChange,changedObject,changedBy, dependencySpace);
  295. }
  296.  
  297. /***********************************|****************************************/
  298.  
  299. pascal void TViewElaspedTimeWithSecondsStatusInfo::DoUpdate(ChangeID theChange, 
  300.                               TObject* changedObject,
  301.                               TObject* changedBy,
  302.                               TDependencySpace* dependencySpace)
  303.  
  304. {
  305.     unsigned long theNum; 
  306.     CStr255 theValue;
  307.     
  308.     Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &theNum, sizeof(theNum), typeLongInteger);
  309.     
  310.     if (gotInfo) {
  311.         long days = theNum / 86400;
  312.         long hours = (theNum - (days*86400)) / 3600;
  313.         long minutes = (theNum - (days*86400) - (hours*3600)) / 60;
  314.         long seconds = theNum % 60;
  315.         sprintf ((char*) &(theValue[1]), "%4d %2d:%02d", days, hours, minutes);
  316.         theValue.Length() = strlen((char*) &(theValue[1]));
  317.         for (short i=1;i <= theValue.Length();i++)
  318.             if (theValue[i] == ' ' )    // Regular space
  319.                 theValue[i] =' ';        // Option-space
  320.     }
  321.     else
  322.         theValue = "";
  323.         
  324.     SetText(theValue,kRedraw);
  325.     inherited::DoUpdate(theChange,changedObject,changedBy, dependencySpace);
  326. }
  327.  
  328. /***********************************|****************************************/
  329.  
  330. pascal DateForm TViewDateStatusInfo::GetDateFormat()
  331.  
  332. {
  333.     return longDate;
  334. };
  335.  
  336. /***********************************|****************************************/
  337.  
  338. pascal DateForm TViewlongDateStatusInfo::GetDateFormat()
  339.  
  340. {
  341.     return longDate;
  342. };
  343.  
  344. /***********************************|****************************************/
  345.  
  346. pascal DateForm TViewshortDateStatusInfo::GetDateFormat()
  347.  
  348. {
  349.     return shortDate;
  350. };
  351.  
  352. /***********************************|****************************************/
  353.  
  354. pascal DateForm TViewabbrevDateStatusInfo::GetDateFormat()
  355.  
  356. {
  357.     return abbrevDate;
  358. };
  359.  
  360. /***********************************|****************************************/
  361.  
  362. pascal void TViewStrStatusInfo::DoUpdate(ChangeID theChange, 
  363.                               TObject* changedObject,
  364.                               TObject* changedBy,
  365.                               TDependencySpace* dependencySpace)
  366.  
  367. {
  368.     CStr255 theText;
  369.     long textSize = sizeof(theText);
  370.     Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &(theText[1]),textSize,typeChar);
  371.     if (gotInfo)
  372.         theText.Length() = (short)textSize;
  373.     else
  374.         theText.Length() = 0;
  375.         
  376.     SetText(theText,kRedraw);
  377.     inherited::DoUpdate(theChange,changedObject,changedBy, dependencySpace);
  378. }
  379.  
  380. /***********************************|****************************************/
  381.  
  382. pascal void TViewlogStatusInfo::Initialize() 
  383.  
  384. {
  385.     fTextList = nil;
  386.     inherited::Initialize();
  387. }
  388.  
  389. /***********************************|****************************************/
  390.  
  391. pascal void TViewlogStatusInfo::DoPostCreate(TDocument* /* itsDocument */)
  392.                         
  393. {    
  394.     FailNIL(fTextList = new TDynamicArray());
  395.     fTextList->IDynamicArray(100,63);    // Initialize with 100 elements of size 63
  396.     DelItemFirst(fNumOfRows);
  397. }
  398.  
  399.  
  400. /***********************************|****************************************/
  401.  
  402. pascal void TViewlogStatusInfo::IRes(TDocument* itsDocument,
  403.                         TView* itsSuperView,
  404.                         TStream* itsParams)
  405.                         
  406. {    
  407.     FailNIL(fTextList = new TDynamicArray());
  408.     fTextList->IDynamicArray(100,63);    // Initialize with 100 elements of size 63
  409.     inherited::IRes(itsDocument,itsSuperView,itsParams);
  410.     DelItemFirst(fNumOfRows);
  411. }
  412.  
  413. /***********************************|****************************************/
  414.  
  415. pascal void TViewlogStatusInfo::AddToLog(CStr255 theText)
  416.                               
  417. {
  418.         short row = (short) (fTextList->GetSize()+1);
  419.         if (row > 99) {
  420.             fTextList->DeleteElementsAt(1,1);
  421.             this->DelItemFirst(1);
  422.             row--;
  423.         }
  424.         VRect theRect;
  425.         CStr255 theTime;
  426.         unsigned long secs;
  427.         GetDateTime(secs);
  428.         IUTimeString(secs,FALSE,theTime);
  429.         theText = theTime + " - " + theText;
  430.         fTextList->InsertElementsBefore(row,(void*) &theText,1);
  431.         InsItemLast(1);
  432.         RowToVRect(row,1,theRect);
  433.         VPoint minToSee(theRect.GetLength(hSel),theRect.GetLength(vSel));
  434.         RevealRect(theRect,minToSee,kRedraw);
  435. }
  436.  
  437. /***********************************|****************************************/
  438.  
  439. pascal void TViewlogStatusInfo::DoUpdate(ChangeID theChange, 
  440.                               TObject* changedObject,
  441.                               TObject* changedBy,
  442.                               TDependencySpace* dependencySpace)
  443.  
  444. {
  445.     CStr255 theText;
  446.     long textSize = sizeof(theText);
  447.     Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &(theText[1]),textSize,typeChar);
  448.     if (gotInfo) {
  449.         theText.Length() = (short)textSize;
  450.         AddToLog(theText);
  451.     }
  452.     inherited::DoUpdate(theChange,changedObject,changedBy, dependencySpace);
  453. }
  454.  
  455. /***********************************|****************************************/
  456.  
  457. pascal void    TViewlogStatusInfo::GetItemText(short index,
  458.                                             CStr255& theText)
  459.                             
  460. {
  461.     if (index>fTextList->GetSize())
  462.         theText = "";
  463.     else
  464.         fTextList->GetElementsAt((ArrayIndex) index,(void*) &theText,1);
  465. }
  466.  
  467. /***********************************|****************************************/
  468.  
  469. pascal void    TViewlogStatusInfo::Free()
  470.                             
  471. {
  472.     delete fTextList;
  473.     inherited::Free();
  474. }
  475.  
  476. TLeftFilledStatusBarView::TLeftFilledStatusBarView()
  477. {
  478.     fStatusBarValues.low = fStatusBarValues.high = fStatusBarValues.current = 0;
  479. }
  480.  
  481. /***********************************|****************************************/
  482.  
  483. #pragma segment MAViewRes
  484. pascal void TLeftFilledStatusBarView::Draw(const VRect& area)//Override
  485.  
  486. {
  487.     //    Get the rectangle which encloses this view.
  488.     CRect statusBarRect;
  489.     GetDrawableQDRect ( statusBarRect );
  490.     
  491.     //    Now, draw the 'left' part as a black filled rectangle.
  492.     if (fStatusBarValues.high - fStatusBarValues.low) {
  493.         float percentFilled = (fStatusBarValues.current / (fStatusBarValues.high - fStatusBarValues.low) );
  494.         CRect leftHalf = statusBarRect;
  495.         leftHalf.right = (short) (percentFilled * (leftHalf.right - leftHalf.left));
  496.         FillRect (leftHalf, (ConstPatternParam) &qd.black);
  497.         
  498.         CRect rightHalf = statusBarRect;
  499.         rightHalf.left = leftHalf.right + 1;
  500.         
  501.         PenNormal();
  502.         FrameRect ( rightHalf );
  503.     }
  504.     else
  505.     {
  506.         PenNormal();
  507.         FrameRect(statusBarRect );
  508.     }
  509.     
  510.     inherited::Draw (area);
  511. }
  512.  
  513. /***********************************|****************************************/
  514.  
  515. #pragma segment MAEvtHandlerRes
  516. pascal void TLeftFilledStatusBarView::DoUpdate(ChangeID theChange,
  517.                                   TObject* changedObject,
  518.                                   TObject* changedBy,
  519.                                   TDependencySpace* dependencySpace)//Override
  520.  
  521. {
  522.     StatusBarValuesRec values; 
  523.     long numSize = sizeof(values);
  524.  
  525.     Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &values, numSize, typeLongInteger);
  526.     if (gotInfo)
  527.     {
  528.         fStatusBarValues = values;
  529.     }
  530.     else
  531.     {
  532.         fStatusBarValues.low = fStatusBarValues.high = fStatusBarValues.current = 0;
  533.     }
  534.     
  535.     //    Invalidate the rect for the status bar item.
  536.     CRect ourFrame;
  537.     GetDrawableQDRect ( ourFrame );
  538.     InvalidateRect ( ourFrame );
  539.  
  540.     inherited::DoUpdate (theChange, changedObject, changedBy, dependencySpace);
  541. }
  542.  
  543. /***********************************|****************************************/
  544.  
  545. pascal void TMonitorButton::DoUpdate(ChangeID theChange,
  546.                                   TObject* changedObject,
  547.                                   TObject* changedBy,
  548.                                   TDependencySpace* dependencySpace)//Override
  549.  
  550. {
  551.     CStr255 theText;
  552.     long textSize = sizeof(theText);
  553.     Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &(theText[1]),textSize,typeChar);
  554.     if (gotInfo) {
  555.         theText.Length() = (short)textSize;
  556.         SetText(theText,kRedraw);
  557.     }
  558.     inherited::DoUpdate(theChange,changedObject,changedBy, dependencySpace);
  559. }
  560.  
  561. pascal void TMonitorButton::DoEvent(EventNumber eventNumber, TEventHandler* source,
  562.                                 TEvent* event)//Override
  563. {
  564.     if (eventNumber == mButtonHit)
  565.         ((TDocumentSecondStomach*) fDocument)->SendButtonMessage(fIdentifier);
  566.     else
  567.         inherited::DoEvent(eventNumber,source,event);
  568. }
  569.  
  570. /***********************************|****************************************/
  571. /***********************************|****************************************/
  572.  
  573. pascal CompareResult TStatusItemList::CompareElements(void* Element1, void* Element2)
  574.  
  575. {
  576.     long e1 = ((TStatusItem*)Element1)->GetID();
  577.     long e2 = ((TStatusItem*)Element2)->GetID();
  578.     
  579.     if (e1 == e2)
  580.         return kItem1EqualItem2;
  581.     else
  582.         if (e1 < e2)
  583.             return kItem1LessThanItem2;
  584.         else
  585.             return kItem1GreaterThanItem2;
  586. }
  587.  
  588. /***********************************|****************************************/
  589.  
  590. TStatusItem::TStatusItem()
  591.  
  592. {
  593.     fDataType = typeWildCard;
  594.     fData = nil;
  595.     fDataSize = 0;
  596. }
  597.  
  598. /***********************************|****************************************/
  599.  
  600. pascal void TStatusItem::SetID(IDType theID)
  601.  
  602. {
  603.     fIdentifier = theID;
  604. }
  605.  
  606. /***********************************|****************************************/
  607.  
  608. pascal IDType TStatusItem::GetID()
  609.  
  610. {
  611.     return fIdentifier;
  612. }
  613.  
  614. /***********************************|****************************************/
  615.  
  616. pascal void TStatusItem::SetDescType(DescType dataType)
  617.  
  618. {
  619.     fDataType = dataType;
  620. }
  621.  
  622. /***********************************|****************************************/
  623.  
  624. pascal IDType TStatusItem::GetDescType()
  625.  
  626. {
  627.     return fDataType;
  628. }
  629.  
  630. /***********************************|****************************************/
  631.  
  632. pascal Boolean TStatusItem::GetInfo(void* data, long& dataSize, DescType desiredType)
  633.  
  634. {
  635.     if (fDataSize == 0)
  636.         return FALSE;
  637.     
  638.     if (fDataSize < dataSize)
  639.         dataSize = fDataSize;
  640.  
  641.     if (desiredType == GetDescType())
  642.     {
  643.         BlockMove ( (Ptr) fData, (Ptr) data, dataSize);
  644.         return TRUE;
  645.     }
  646.     else
  647.     {    AEDesc desc;
  648.  
  649.         OSErr err = AECoercePtr ( GetDescType(), fData, fDataSize, desiredType, desc);
  650.         
  651.         if ((err == noErr) && ( desc.descriptorType == desiredType))
  652.         {
  653.             dataSize = GetHandleSize ( desc.dataHandle );
  654.             BlockMove ( (Ptr) *desc.dataHandle, (Ptr) data, dataSize );
  655.  
  656.             if (GetDescType() == typeWildCard)
  657.                 SetInfo ( data, dataSize, desc.descriptorType );
  658.         }
  659.         
  660.         AEDisposeDesc ( desc );
  661.         
  662.         return ( err == noErr );
  663.     }
  664. }
  665.  
  666. /***********************************|****************************************/
  667.         
  668. pascal void TStatusItem::SetInfo(void* data, long dataSize, DescType actualType)
  669. {        
  670.     if (dataSize != fDataSize )
  671.     {
  672.         DisposePtr ( (Ptr) fData );
  673.         fData = NewPtrClear ( dataSize );
  674.     }
  675.     
  676.     if (fData)
  677.     {
  678.         fDataSize = dataSize;
  679.         BlockMove ( (Ptr) data, fData, fDataSize );
  680.         SetDescType ( actualType );
  681.         
  682.         Changed( 0, NULL );     // Notify all dependents
  683.     }
  684.     else
  685.         Changed( 1, NULL );
  686. }
  687.  
  688. /***********************************|****************************************/
  689.  
  690. pascal void TViewMonitorStatus::Initialize() {
  691.     fBlinkStatusTimer = TickCount();
  692.     fOldText = "";
  693.     inherited::Initialize();
  694. }
  695.  
  696. /***********************************|****************************************/
  697.  
  698. pascal void TViewMonitorStatus::SetText(const CStr255& theText,
  699.                                  Boolean redraw)
  700. {
  701.     fOldText = "";
  702.     inherited::SetText(theText,redraw);
  703. }
  704.  
  705. /***********************************|****************************************/
  706.  
  707. pascal void TViewMonitorStatus::SuperViewChangedFrame(const VRect& oldFrame,
  708.                                          const VRect& newFrame,
  709.                                          Boolean invalidate)
  710. {    
  711.         
  712.     VRect myFrame;
  713.     VPoint delta;
  714.     
  715.     inherited::SuperViewChangedFrame(oldFrame,newFrame, invalidate);
  716.     delta = newFrame.GetSize() - oldFrame.GetSize();
  717.     GetFrame(myFrame);
  718.     OffsetVRect(myFrame,0,delta.v);
  719.     SetFrame(myFrame,kRedraw);
  720. }
  721.  
  722. /***********************************|****************************************/
  723.  
  724. pascal void TViewMonitorStatus::BlinkText()
  725.  
  726. {
  727.         unsigned long tickNow = TickCount();
  728.         if ((tickNow - 30) > fBlinkStatusTimer) {
  729.             fBlinkStatusTimer = tickNow;
  730.             CStr255 currentText;
  731.             GetText(currentText);
  732.             if (currentText.Length() == 0) {
  733.                 if (fOldText.Length() != 0) {
  734.                     currentText = fOldText;
  735.                     inherited::SetText(currentText, kRedraw);
  736.                 }
  737.             }
  738.             else {
  739.                 fOldText = currentText;
  740.                 inherited::SetText("", kRedraw);
  741.             }
  742.         }
  743. }
  744.  
  745. /***********************************|****************************************/
  746.  
  747. pascal MenuHandle TFixedPopup::GetMenuHandle()
  748. {
  749.     MenuHandle aMenu = MAGetMenu(this->GetMenuID());
  750.     if (!aMenu)
  751.         aMenu = GetMHandle(this->GetMenuID());
  752.         
  753.     return aMenu;    
  754. }
  755.  
  756. /***********************************|****************************************/
  757. const IDType kBulletTextBehavior = 'bult';
  758.  
  759. const char kBulletChar = '•';
  760.  
  761. class TBulletTextBehavior : public TBehavior
  762. {
  763. public:
  764.     TBulletEditText* fBulletEditText;
  765.  
  766.     virtual pascal void IBulletTextBehavior(IDType itsIdentifier, TBulletEditText* itsEditText);
  767.  
  768.     virtual pascal void DoCommandKeyEvent(TToolboxEvent* event);    // override
  769.  
  770.     virtual pascal void DoKeyEvent(TToolboxEvent* event);    // override
  771.  
  772.     virtual pascal void DoMenuCommand(CommandNumber aCommandNumber);    // override
  773.  
  774. };
  775.  
  776. //----------------------------------------------------------------------------------------
  777. #pragma segment DlgOpen
  778. pascal void TBulletEditText::Initialize()    // Override 
  779. {
  780.     inherited::Initialize();
  781.     
  782.     fRealDataHandle = nil;
  783.     fBulletTextBehavior = nil;
  784. }
  785.  
  786. //----------------------------------------------------------------------------------------
  787. #pragma segment DlgClose
  788. pascal void TBulletEditText::Free()    // Override 
  789. {
  790.     fRealDataHandle = (CStringHandle)DisposeIfHandle((Handle)fRealDataHandle);
  791.     TBehavior* aBehavior = fBulletTextBehavior;        // free it after inherited Free
  792.  
  793.     inherited::Free();
  794.  
  795.     FreeIfObject(aBehavior);
  796. }
  797.  
  798. //----------------------------------------------------------------------------------------
  799. #pragma segment DlgRes
  800. pascal TDialogTEView* TBulletEditText::GetTEView()    // Override 
  801. {
  802.     if (!fBulletTextBehavior) {
  803.         TBulletTextBehavior* aBehavoir = new TBulletTextBehavior;
  804.         aBehavoir->IBulletTextBehavior(kBulletTextBehavior, this);
  805.         fBulletTextBehavior = aBehavoir;
  806.     }
  807.  
  808.     TDialogTEView* result = inherited::GetTEView();
  809.     
  810.     if (result) {
  811.         result->AddBehavior(fBulletTextBehavior);
  812.     }
  813.     
  814.     return result;
  815. } // TBulletEditText::GetTEView 
  816.  
  817. //----------------------------------------------------------------------------------------
  818. #pragma segment DlgRes
  819. pascal void TBulletEditText::GetRealText(CStr255& theText)    
  820. {
  821.     if (fRealDataHandle)
  822.         CopyStr255((**((String255Handle)fRealDataHandle)), (Ptr)&theText);
  823.     else
  824.         theText = gEmptyString;
  825. } // TBulletEditText::GetRealText 
  826.  
  827. //----------------------------------------------------------------------------------------
  828. #pragma segment DlgRes
  829. pascal void TBulletEditText::ReleaseTEView()
  830. {
  831.     if (fTEView && fBulletTextBehavior) {
  832.         fTEView->RemoveBehavior(fBulletTextBehavior);
  833.     }
  834.  
  835.     inherited::ReleaseTEView();
  836. } // TBulletEditText::ReleaseTEView 
  837.  
  838. //----------------------------------------------------------------------------------------
  839. #pragma segment DlgNonRes
  840. pascal void TBulletEditText::StopEdit()
  841. {
  842.     if (fTEView)
  843.     {
  844.         CStr255 aString;
  845.  
  846.         fTEView->SetActive(FALSE);                // Hides the selection
  847.         this->GetRealText(aString);                // Must get the REAL text before removing
  848.                                                 // the floating TEView 
  849.         this->RemoveFloatingTEView();
  850.         this->SetText(aString, kDontRedraw);
  851.     }
  852. } // TBulletEditText::StopEdit 
  853.  
  854. //----------------------------------------------------------------------------------------
  855. #pragma segment DlgNonRes
  856. pascal void TBulletEditText::SetText(const CStr255& theText,
  857.                                  Boolean redraw)
  858. {
  859.     if (!fRealDataHandle || (CompareStrings(theText,(**((String255Handle)fRealDataHandle))) != 0 )) {
  860.         fRealDataHandle = (CStringHandle)DisposeIfHandle((Handle)fRealDataHandle);
  861.         fRealDataHandle = NewString(theText);
  862.         if (MemError() != noErr)
  863.             fRealDataHandle = NULL;
  864.     }
  865.             
  866.     CStr255 secureText = "";
  867.     for (short i = 1; i <= theText.Length(); i++) {
  868.         secureText += kBulletChar;
  869.     }
  870.  
  871.     if (fTEView) {
  872.         fTEView->SetText(secureText);
  873.         fTEView->RecalcText();
  874.         fTEView->SynchView(kDontRedraw);
  875.         if (redraw && this->IsDrawable()) {
  876.             VRect area;
  877.             CRect qdArea;
  878.         
  879.             this->ControlArea(area);
  880.             this->ViewToQDRect(area, qdArea);
  881.             EraseRect(qdArea);
  882.             this->HandleDraw(area);
  883.         }
  884.     } else {
  885.         if (!fDataHandle || (CompareStrings(secureText,(**((String255Handle)fDataHandle))) != 0 )) {
  886.             this->ReleaseText();
  887.             fDataHandle = NewString(secureText);
  888.             if (MemError() != noErr)
  889.                 fDataHandle = NULL;
  890.             if (redraw && this->IsDrawable()) {
  891.                 VRect area;
  892.                 CRect qdArea;
  893.     
  894.                 this->ControlArea(area);
  895.                 this->ViewToQDRect(area, qdArea);
  896.                 EraseRect(qdArea);
  897.                 this->HandleDraw(area);
  898.             }
  899.         }
  900.     }
  901. } // TBulletEditText::SetText 
  902.  
  903. //----------------------------------------------------------------------------------------
  904. #pragma segment DlgRes
  905. pascal void TBulletEditText::AddCharacter(char ch)
  906. {
  907.     if (fTEView) {
  908.         TEHandle theHTE = fTEView->fHTE;
  909.         short start = (**theHTE).selStart;
  910.         short end = (**theHTE).selEnd;
  911.         
  912.         CStr255 theText;
  913.         this->GetRealText(theText);
  914.         CStr255 insertText = "";
  915.         insertText += ch;
  916.         if (start - end)
  917.             theText.Delete(start+1, end-start);
  918.         theText.Insert(insertText, start+1);
  919.         
  920.         if (fRealDataHandle) {
  921.             SetString(fRealDataHandle, theText);
  922.         } else {
  923.             fRealDataHandle = (CStringHandle)DisposeIfHandle((Handle)fRealDataHandle);
  924.             fRealDataHandle = NewString(theText);
  925.             if (MemError() != noErr)
  926.                 fRealDataHandle = NULL;
  927.         }
  928.     }
  929. } // TBulletEditText::AddCharacter 
  930.  
  931. //----------------------------------------------------------------------------------------
  932. #pragma segment DlgRes
  933. pascal void TBulletEditText::DelChars()
  934. {
  935.     if (fTEView) {
  936.         TEHandle theHTE = fTEView->fHTE;
  937.         short start = (**theHTE).selStart;
  938.         short length = (short)Min(kStr255Len, (**theHTE).selEnd - start);        //!!! long->short
  939.         if (length == 0) {
  940.             start -= 1;
  941.             length = 1;
  942.         }
  943.         
  944.         if ((start >= 0) && (length > 0)) {
  945.             CStr255 theText;
  946.             this->GetRealText(theText);
  947.             theText.Delete(start+1, length);
  948.             
  949.             if (fRealDataHandle)
  950.                 SetString(fRealDataHandle, theText);
  951.         }
  952.     }
  953. } // TBulletEditText::DelChars 
  954.  
  955. //----------------------------------------------------------------------------------------
  956. #pragma segment DlgRes
  957. pascal void TBulletTextBehavior::IBulletTextBehavior(IDType itsIdentifier, TBulletEditText* itsEditText)
  958. {
  959.     this->IBehavior(itsIdentifier);
  960.     
  961.     fBulletEditText = itsEditText;
  962. } // TBulletTextBehavior::IBulletTextBehavior
  963.  
  964. //----------------------------------------------------------------------------------------
  965. #pragma    segment    ASelCommand
  966. pascal void TBulletTextBehavior::DoCommandKeyEvent(TToolboxEvent* event)
  967. {
  968. } // TBulletTextBehavior::DoCommandKeyEvent
  969.  
  970. //----------------------------------------------------------------------------------------
  971. #pragma segment DlgRes
  972. pascal void TBulletTextBehavior::DoKeyEvent(TToolboxEvent* event)
  973. {
  974.     unsigned char ch = event->fCharacter;
  975.     
  976.     if ((ch >= 0x20) && (ch <= 0x7F)) {
  977.         if (fBulletEditText)
  978.             fBulletEditText->AddCharacter(ch);
  979.         event->fCharacter = kBulletChar;
  980.     } else if (ch > 0x7F) {
  981.         SysBeep(4);
  982.         return;
  983.     } else if (ch == chBackspace) {
  984.         if (fBulletEditText)
  985.             fBulletEditText->DelChars();
  986.     }
  987.     
  988.     inherited::DoKeyEvent(event);
  989.     
  990. } // TBulletTextBehavior::DoKeyEvent
  991.  
  992. //----------------------------------------------------------------------------------------
  993. #pragma segment ASelCommand
  994. pascal void TBulletTextBehavior::DoMenuCommand(CommandNumber aCommandNumber)
  995.  
  996. {
  997.     TBehavior * nextBehavior = this->GetNextEnabledBehavior();
  998.  
  999.     if ((aCommandNumber >= cEditBase) && (aCommandNumber <= cEditLast))
  1000.         SysBeep(4);
  1001.     else
  1002.         inherited::DoMenuCommand(aCommandNumber);
  1003. } // TBulletTextBehavior::DoMenuCommand
  1004.  
  1005.